<template>
  <j-modal
    :title="'质量分析'"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :fullscreen="false"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
    cancelText="关闭"
  > 
    <template slot="footer">
      <a-button @click="handleCancel">关闭</a-button> 
    </template>
    <a-spin :spinning="confirmLoading"> 
        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          class="j-table-force-nowrap"
          :scroll="{ x: true }"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="false"
          :loading="loading"
          @change="handleTableChange"
        >
        </a-table> 
    </a-spin>
    <weight-analyse-modal ref="modalForm" @ok="modalFormOk"></weight-analyse-modal>
  </j-modal>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JMultiSelectTag from '@/components/dict/JMultiSelectTag'
import LineChartMultid from '@/components/chart/LineChartMultid'
import dateFormat from '@/components/jeecg/JEasyCron/format-date'
import WeightAnalyseModal from './WeightAnalyseModal'
export default {
  name: 'ExtractModal',
  mixins: [JeecgListMixin],
  components: {
    JMultiSelectTag,
    LineChartMultid,
    WeightAnalyseModal,
  },
  data() {
    return {
      title: '',
      dataSetId:0,
      width: 900,
      height: 500,  
      visible: false,
      disableSubmit: false,
      // url: {
      //   list: "/dataHistory/dataHistory/list"
      // },
      model: {
        propName: '',
      },
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        }
      ],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false, 
    }
  },
  methods: {
     show(id) {  
      this.columns =  []
      this.dataSource =  []
      this.dataSetId = id;
      this.loadDataProperty() 
    },
    loadDataProperty() {
      var that = this
      httpAction('/dataProperty/dataProperty/list?pageSize=99999', {}, 'get')
        .then((res) => {
          if (res.success) {
            that.dataPropertyList = res.result.records
            that.loadDetailData()
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {})
    },
    getPropertyText(key) {
      let filterList = this.dataPropertyList.filter((item) => item.propNo == key)
      if (filterList.length > 0) {
        return filterList[0].propName
      }
      return key
    }, 
   
    loadDetailData() { 
      var that = this;
      this.visible = true
      this.confirmLoading = true
      httpAction('/dataSet/dataSet/queryByIdQuality?id='+that.dataSetId, {}, 'get')
        .then((res) => { 
          if (res.success) { 
            var list = []
            //var data = res.result.records
            var data = res.result 
            this.columns =[{
                title: '',
                dataIndex: 'type',
                key: 'type',
                width: 60,
                align: 'center', 
              }]
            for (const key in data['null_values']) {
              that.columns.push( {
                  title: that.getPropertyText(key),
                  align: 'center',
                  dataIndex: key,
              }) 
            } 
            data['null_values']['type']='NULL值数量'
            that.dataSource = [data['null_values']];
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.confirmLoading = false
        })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      this.$emit('close')
      this.visible = false
    }, 
    handleCancel() {
      this.close()
    }
  },
}
</script>